from utils.core import DBConnector, FastTextClassifier

remote_db_config = {
    'user': 'common',
    'password': '123456',
    'host': '127.0.0.1',
    'database': 'poa_news',
    'raise_on_warnings': True
}

if __name__ == "__main__":
    db = DBConnector()
    if db.connect() == False:
        print("can't access database")
        exit()

    dbData = db.query((
        "SELECT t1.news_id,title,category,content "
        "FROM main AS t1 JOIN "
        "(SELECT news_id FROM main ORDER BY RAND() LIMIT 10) "
        "as t2 ON t1.news_id=t2.news_id;"))

    ftc = FastTextClassifier()

    ftc.train_model(
        model="quantized_model.bin")

    for obj in dbData:
        print(obj["news_id"], obj["category"])
        print(ftc.classify(obj["content"]))
